<!--
 * @Description: 
 * @Autor: starzhou
 * @Date: 2020-08-31 20:34:35
 * @LastEditTime: 2020-09-09 13:38:27
-->
<template>
    <div>
        <template v-for="(item,index) in menus">
            <el-submenu :index="item.id+''" v-if="item.children" :key="'p_'+index">
                <template slot="title">
                    <i class="nav_icon" :class="item.icon"></i>
                    <span slot="title" class="left-menu--text">{{item.menuName}}</span>
                    <i class="navLevel1_top"></i>
                    <i class="navLevel1_bottom"></i>
                </template>
                <v-app-menu :menus="item.children"/>
            </el-submenu>
            <el-menu-item v-if="!item.children && !item.dataId" :key="'p_s_'+index" :index="item.path+''">
                <i class="nav_icon" :class="item.icon"></i>
                <span slot="title" class="left-menu--text">{{item.menuName}}</span>
                <i class="navLevel1_top"></i>
                <i class="navLevel1_bottom"></i>
            </el-menu-item>
            <el-menu-item v-if="!item.children && item.dataId" :key="'p_s_'+index" :index="item.path+'/'+item.dataId">
                <i class="nav_icon" :class="item.icon"></i>
                <span slot="title" class="left-menu--text">{{getmenutext(item)}}</span>
                <i class="nav_operate_icon nav_operate_icon_edit" @click.stop="editCase(item)">E</i>
                <i class="nav_operate_icon nav_operate_icon_delete" @click.stop="deletcCase(item)">D</i>
                <i class="navLevel1_top"></i>
                <i class="navLevel1_bottom"></i>
            </el-menu-item>
        </template>
    </div>
</template>
<script>
export default {
  name: 'v-app-menu',
  props: ['menus'],
  data(){
      return{

      }
  },
   methods:{
       editCase(item){
           if (item.path == '/reportCenter') {
                this.editFolder(item)
           } else if(item.path == '/monitor'){
               this.$router.push({path: '/editCase'});
           }
       },
       deletcCase(item){
           if (item.path == '/reportCenter') {
                this.delFolder(item)
           } else if(item.path == '/monitor'){
                this.deleteCase(item);
           }
       },
       getmenutext (item) {
           return item.menuName
       },
       // 修改文件夹
       editFolder (item) {
           this.$prompt('', '修改报告中心文件夹', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
            }).then(({value}) => {
                this.$Api.editFolder({
                    id: item.dataId,
                    folderName: value
                }).then(() => {
                    this.$store.dispatch('getInfo')
                })
            })
       },
       //删除报告文件夹
       delFolder (item) {
            this.$confirm( '删除文件夹, 是否继续?', '删除文件夹', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$Api.delFolder(item.dataId).then(() => {
                    this.$store.dispatch('getInfo')
                })
            })
        },
        deleteCase(item){ // 删除方案
            this.$confirm( '删除方案, 是否继续?', '删除方案', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$Api.delScheme(item.dataId).then(res => {
                    console.log(res);
                    if(res.code == '200'){
                        this.$store.dispatch('getInfo')
                    }
                })
            })
      }
   }
}
</script>
